package com.mobilesales.android;

import com.mobilesales.android.activities.clients.Clients;
import com.mobilesales.android.activities.common.SettingsActivity;
import com.mobilesales.android.activities.tasks.Tasks;
import com.mobilesales.android.infrastructure.MenuBuilder;
import com.mobilesales.android.infrastructure.MenuItem;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MobileSalesActivity extends ListActivity {

    private ArrayAdapter<MenuItem> menuItems;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        this.buildMenu();        
    }
    
    public void buildMenu() {
        menuItems = new MenuBuilder(this)
						.addItem(new MenuItem(Clients.class, getString(R.string.Clients)))
        				.addItem(new MenuItem(Tasks.class, getString(R.string.Tasks)))
        				.addItem(new MenuItem(SettingsActivity.class, getString(R.string.Settings)))
        				.build();
    	this.setListAdapter(menuItems);
    }
    
	@Override
	protected void onListItemClick(ListView listView, View view, int position,long id) {
		super.onListItemClick(listView, view, position, id);
		MenuItem menuItem = (MenuItem) this.menuItems.getItem(position);
		Intent intent = new Intent(this, menuItem.getActivityClass());
		startActivity(intent);
	}
}




